//
//  JHEditViewController.m
//  Job
//
//  Created by 桑赐相 on 2018/9/1.
//  Copyright © 2018年 桑赐相. All rights reserved.
//

#import "JHEditViewController.h"

@interface JHEditViewController ()<UITextViewDelegate>
@property (weak, nonatomic) IBOutlet UITextView *editView;
@property (nonatomic,strong) UIBarButtonItem *submitItem;
@end

@implementation JHEditViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"意见反馈";
    self.editView.placeholder = @"提出您的想法或意见....";
    self.editView.delegate = self;
    self.submitItem = [[UIBarButtonItem alloc]initWithTitle:@"提交" style:UIBarButtonItemStylePlain target:self action:@selector(submitAction)];
    self.submitItem.enabled = NO;
    self.navigationItem.rightBarButtonItem = self.submitItem;
    
}
-(void)submitAction{
 
    MBProgressHUD *hud = [MBProgressHUD showMessage:@"提交中..."];
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[@"content"] = self.editView.text;
    dict[@"name"] = @"小明";
    [HTTPTools POST:@"/api/opinion" parameters:dict callback:^(id result, NSString *msg, NSError *error) {
        [hud hideAnimated:YES];
        if (!error) {
            if (!msg) {
                WeakSelf(weakSelf);
                [self openAlertControllerTitle:@"感谢你的宝贵意见!" message:nil style:UIAlertControllerStyleAlert actionTitle1:@"确定" actionTitle2:nil callback:^(int index) {
                    [weakSelf popViewController];
                }];
            }else{
                [iToast showCenter:msg];
            }
        }
    }];
}



- (void)textViewDidChange:(UITextView *)textView{
    NSLog(@"%@",textView.text);
    if (textView.text.length <= 0) {
        self.submitItem.enabled = NO;
    }else{
        self.submitItem.enabled = YES;
    }
}





@end
